/*
 *  $Id: Complex.cs 1046 2010-05-18 12:17:04Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

namespace Ragima {
    /// <summary>
    /// Комплексная раса, являющаяся набором нескольких других рас
    /// </summary>
    public class ComplexRace: Race {
        private List<Race> _subRaces;

        public ComplexRace(string nameId, params Race[] subRaces): base(nameId) {
            _subRaces = new List<Race>(subRaces);
        }

        public List<Race> SubRaces {
            get { return _subRaces; }
        }

        public override bool IsRace(Race race) {
            if (race is ComplexRace) {
                ComplexRace other = (ComplexRace) race;
                foreach (Race sub in other.SubRaces)
                    if (!IsRace(sub))
                        return false;
                return true;
            } else {
                foreach (Race sub in _subRaces)
                    if (sub.IsRace(race))
                        return true;
                return false;
            }
        }

        public override void SetNaturalAffects(CreatureCard card, ICollector<Affect> affects) {
            foreach (Race sub in _subRaces)
                sub.SetNaturalAffects(card, affects);
        }
        public override void SetAbilities(CreatureCard card, ICollector<AbilityCard> abilities) {
            foreach (Race sub in _subRaces)
                sub.SetAbilities(card, abilities);
        }
    }
}